package com.dongdong.controller;


import com.dongdong.aspect.LogAn;
import com.dongdong.service.SpecService;
import com.dongdong.utils.PageBean;
import com.dongdong.utils.PageResult;
import com.dongdong.utils.Result;
import com.dongdong.vo.SpecVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/spec")
public class SpecController {

    @Autowired
    private SpecService specService;


    @LogAn
    @PostMapping("/getSpecByPageLike")
    public Result<SpecVO> getSpecByPageLike(@RequestBody PageBean<SpecVO> pageBean){
        PageResult<SpecVO> pageResult = specService.getSpecByPageLike(pageBean);
        return Result.OK().setData(pageResult);
    }

    @GetMapping("/getSpecList")
    public Result getSpecList(){
        List<SpecVO> specVOS = specService.getSpecList();
        return Result.OK().setData(specVOS);
    }


    @PostMapping("addSpec")
    public Result addSpec(@RequestBody SpecVO specVO){
        specService.addSpec(specVO);
        return Result.OK();
    }

    @GetMapping("/getSpecAndOptionById")
    public Result<SpecVO> getSpecAndOptionById(@RequestParam Long id){
        SpecVO specVO = specService.getSpecAndOptionById(id);
        return Result.OK().setData(specVO);
    }


    @PutMapping("/updateSpecAndOption")
    public Result updateSpecAndOption(@RequestBody SpecVO specVO){
        specService.updateSpecAndOption(specVO);
        return Result.OK();
    }

    @DeleteMapping("deleteSpecAndOption")
    public Result deleteSpecAndOption(@RequestParam Long id){
        specService.deleteSpecAndOption(id);
        return Result.OK();
    }
}
